package com.hjxr.framework.config;

import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Springboot 方式 的 MybatisPlus配置类
 *
 * @author sun
 * @version v1.0
 * @since 2020-08-28
 */
@EnableTransactionManagement
@Configuration
@MapperScan("com.hjxr.**.**.mapper")
public class MybatisPlusConfig {
  /**
   * 分页插件
   *
   * @return
   */
  @Bean
  public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    return paginationInterceptor.setOverflow(true);
  }

  /**
   * MyBatisPlus逻辑删除，需要在yml中配置开启
   * 3.0.7.1版本的LogicSqlInjector直接extends DefaultSqlInjector, 以后可以直接取得LogicSqlInjector
   */
  @Bean
  public ISqlInjector sqlInjector() {
    return new DefaultSqlInjector();
  }

  @Bean
  public OracleKeyGenerator oracleKeyGenerator() {
    return new OracleKeyGenerator();
  }
}
